package zhongbo.java.air.fightpath.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.Topic;
import zhongbo.java.air.fightpath.listener.RedisSubscribeLogChanelListener;
import zhongbo.java.air.fightpath.listener.RedisSubscribeMyFlightPathChanelListener;
/**
 * 配置redis Sub订阅监听者listener
 */

@Configuration
@Slf4j
public class RedisListenerConfig {
    public static String LOG_CHANEL = "log_channel";
    public static String MY_FLIGHT_PATH_CHANEL = "injest_flight_path_chen_xiao_qi";

    public static String CHANEL = "live_flight_path_chen_xiao_qi";





    /**
     * 配置redis  listenerContainer 监听容器 ，添加 logChanelListener 监听器到容器里，同时指定 chanel 名称为 log_chanel
     *
     * @param listenerContainer 注入 listenerContainer
     *                          （在common模块里，已经配置了这个bean，直接使用即可）
     * @param logChanelListener redis日志频道监听器
     *                          （自建RedisSubscribeLogChanelListener类，继承了MessageListener接口）
     */
    @Autowired
    public void configListener(RedisMessageListenerContainer listenerContainer,
                               RedisSubscribeLogChanelListener logChanelListener,
                               RedisSubscribeMyFlightPathChanelListener myListener
                               ) {

        log.info("配置redis监听器");
        //配置 RedisSubscribeLogChanelListener 监听频道 log_chanel 订阅
        Topic logTopic = new PatternTopic((LOG_CHANEL));
        Topic myTopic = new PatternTopic((MY_FLIGHT_PATH_CHANEL));

//        Topic logTopic = new Topic(LOG_CHANEL);
        listenerContainer.addMessageListener(logChanelListener, logTopic);
        listenerContainer.addMessageListener(myListener, myTopic);


    }



}
